import numpy as np
import cv2


def liner():
    labels = ["cat", "dog"]
    np.random.seed(1)  # 随机数种子
    # 随机生成权重矩阵和偏差矢量
    w = np.random.randn(2, 3072)  # 在[0,1]范围内采样
    b = np.random.randn(2)
    raw_image = cv2.imread("../../dataset/dog_cat/cat.100.jpg")
    image = cv2.resize(raw_image, (32, 32)).flatten()  # .flatten()展平函数
    # 应用评分函数
    scores = w.dot(image) + b
    for label, score in zip(labels, scores):
        print(f"[info]:{label}--{score:.2f}")
    cv2.putText(raw_image, f"label:{labels[np.argmax(scores)]}",
                (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.9,
                (0, 255, 0), 2)
    cv2.imshow("Image", raw_image)
    cv2.waitKey(0)


if __name__ == '__main__':
    liner()